﻿// ------------------------------------------------------------------------------------
//      Copyright (c) 2012 uhavemyword@gmail.com. All rights reserved.
//      Created by Ben at 12/24/2012 7:13:16 PM
// ------------------------------------------------------------------------------------

namespace CP.NLayer.Models.Entities
{
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Runtime.Serialization;
    using CP.NLayer.Models.LocalizedDataAnnotations;
    using CP.NLayer.Resources.Model;

    [DataContract(IsReference = true)]
    public class Role : EntityBase
    {
        private ICollection<User> _users;
        private ICollection<Permission> _permissions;

        #region Ctor
        public Role()
        {
            this.Users = new List<User>();
            this.Permissions = new List<Permission>();
        }
        #endregion

        #region Properties
        [DataMember]
        [Required2, StringLength2(50)]
        [Display(Name = MResourceNames.Role_Name, ResourceType = typeof(MResources))]
        public string Name { get; set; }

        [DataMember]
        [StringLength2(200)]
        [Display(Name = MResourceNames.Description, ResourceType = typeof(MResources))]
        public string Description { get; set; }
        #endregion

        #region Navigation Properties
        [DataMember]
        public virtual ICollection<User> Users
        {
            get { return _users ?? (_users = new List<User>()); }
            protected set { _users = value; }
        }

        [DataMember]
        public virtual ICollection<Permission> Permissions
        {
            get { return _permissions ?? (_permissions = new List<Permission>()); }
            protected set { _permissions = value; }
        }
        #endregion

        #region Methods
        public override string ToString()
        {
            return this.Name;
        }
        #endregion
    }
}
